package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.config.battle.PatronsBattleDetail;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.entity.unioncampwar.*;
import com.yanqu.road.entity.unioncampwar.patrons.UnionCampWarLockPatronsData;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.pb.unionCampWar.UnionCampWar;

import java.math.BigInteger;
import java.util.List;

public class UnionCampWarPb {
    public static UnionCampWar.UnionCampWarMarqueeInfoTemp.Builder parseMarqueeInfoMsg(UnionCampWarNoticeData noticeData, PlayerProto.PlayerBaseTempMsg.Builder playerBaseTempMsg) {
        UnionCampWar.UnionCampWarMarqueeInfoTemp.Builder builder = UnionCampWar.UnionCampWarMarqueeInfoTemp.newBuilder();
        builder.setCampId(noticeData.getAttackCampId());
        builder.setDefendCampId(noticeData.getDefendCampId());
        builder.setHoldId(noticeData.getHoldId());
        builder.setDefendUnionName(noticeData.getDefendUnionName());
        builder.setWinNum(noticeData.getWinNum());
        builder.setTime(noticeData.getBattleTime());
        builder.setUserBaseInfo(playerBaseTempMsg);
        return builder;
    }

    public static UnionCampWarLockPatronsData parseLockPatronData(String unionId, UserPatrons userPatrons) {
        UnionCampWarLockPatronsData lockPatronsData = new UnionCampWarLockPatronsData(unionId, userPatrons.getUserId(), userPatrons.getPatronsId());
        lockPatronsData.setLevel(userPatrons.getLevel());
        lockPatronsData.setSkin(userPatrons.getSkinId());
        lockPatronsData.setPromotionId(userPatrons.getShowPromotionId());
        lockPatronsData.setStar(userPatrons.getStageLv());
        lockPatronsData.setQuality((int) userPatrons.getQualification());
        lockPatronsData.setAbility(BigInteger.ZERO.add(userPatrons.getAbility()));

        return lockPatronsData;
    }

    public static UnionCampWarLockPatronsData parseLockPatronData(String unionId, long userId, PatronsProto.PatronsSimpleTempMsg patronsSimpleTempMsg) {
        UnionCampWarLockPatronsData lockPatronsData = new UnionCampWarLockPatronsData(unionId, userId, patronsSimpleTempMsg.getPatronsId());
        lockPatronsData.setLevel(patronsSimpleTempMsg.getLevel());
        lockPatronsData.setSkin(patronsSimpleTempMsg.getSkinId());
        lockPatronsData.setPromotionId((int) patronsSimpleTempMsg.getPromotionId());
        lockPatronsData.setStar(patronsSimpleTempMsg.getStageLv());
        lockPatronsData.setQuality((int) patronsSimpleTempMsg.getQuality());
        lockPatronsData.setAbility(new BigInteger(patronsSimpleTempMsg.getAbility()));

        return lockPatronsData;
    }

    public static UserPatrons parseUserPatronsByLockPatrons(UnionCampWarLockPatronsData lockPatronsData) {
        UserPatrons userPatrons = new UserPatrons();
        userPatrons.setUserId(lockPatronsData.getUserId());
        userPatrons.setPatronsId(lockPatronsData.getPatronsId());
        userPatrons.setLevel(lockPatronsData.getLevel());
        userPatrons.setStageLv(lockPatronsData.getStar());
        userPatrons.setSkinId(lockPatronsData.getSkin());
        userPatrons.setPromotionId(lockPatronsData.getPromotionId());
        userPatrons.setQualification(lockPatronsData.getQuality());
        userPatrons.setAbility(BigInteger.ZERO.add(lockPatronsData.getAbility()));
        userPatrons.setTotalBlood(BigInteger.ZERO.add(lockPatronsData.getAbility()));
        userPatrons.setCurrentBlood(BigInteger.ZERO.add(lockPatronsData.getAbility()));

        return userPatrons;
    }

    public static UserPatrons parseUserPatronsByPatronsMsg(long userId, PatronsProto.PatronsSimpleTempMsg patronsSimpleTempMsg) {
        UserPatrons userPatrons = new UserPatrons();
        userPatrons.setUserId(userId);
        userPatrons.setPatronsId(patronsSimpleTempMsg.getPatronsId());
        userPatrons.setLevel(patronsSimpleTempMsg.getLevel());
        userPatrons.setStageLv(patronsSimpleTempMsg.getStageLv());
        userPatrons.setSkinId(patronsSimpleTempMsg.getSkinId());
        userPatrons.setPromotionId((int) patronsSimpleTempMsg.getPromotionId());
        userPatrons.setQualification(patronsSimpleTempMsg.getQuality());
        userPatrons.setAbility(new BigInteger(patronsSimpleTempMsg.getAbility()));
        userPatrons.setTotalBlood(new BigInteger(patronsSimpleTempMsg.getBlood()));
        userPatrons.setCurrentBlood(new BigInteger(patronsSimpleTempMsg.getBlood()));

        return userPatrons;
    }

    public static UnionCampWar.UnionCampWarBattleDetailTempMsg.Builder parseBattleDetailTempMsg(PatronsBattleDetail battleDetail) {
        if (null == battleDetail) {
            return null;
        }
        UnionCampWar.UnionCampWarBattleDetailTempMsg.Builder msg = UnionCampWar.UnionCampWarBattleDetailTempMsg.newBuilder();
        msg.setMyPatronsId(battleDetail.getMyPatronsId());
        msg.setMyPatronsBlood(battleDetail.getMyPatronsTotalBlood().toString());
        msg.setMyPatronsCurrentBlood(battleDetail.getMyPatronsCurrentBlood().toString());
        msg.setEnemyUserId(battleDetail.getEnemyUserId());
        msg.setEnemyPatronsId(battleDetail.getEnemyPatronsId());
        msg.setEnemyPatronsBlood(battleDetail.getEnemyPatronsTotalBlood().toString());
        msg.setEnemyPatronsCurrentBlood(battleDetail.getEnemyPatronsCurrentBlood().toString());
        msg.setMyPatronsBloodRevert(battleDetail.getMyPatronsRevertBlood().toString());
        return msg;
    }

    public static UnionCampWar.UnionCampWarBattleDetailListMsg.Builder parseBattleDetailListMsg(List<PatronsBattleDetail> battleDetailList) {
        UnionCampWar.UnionCampWarBattleDetailListMsg.Builder listMsg = UnionCampWar.UnionCampWarBattleDetailListMsg.newBuilder();
        if (null != battleDetailList) {
            for (PatronsBattleDetail battleDetail : battleDetailList) {
                UnionCampWar.UnionCampWarBattleDetailTempMsg.Builder msg = parseBattleDetailTempMsg(battleDetail);
                if (null != msg) {
                    listMsg.addBattleDetailList(msg);
                }
            }
        }
        return listMsg;
    }

    public static UnionCampWar.UnionCampBoxNoticeTemp.Builder parseBoxNoticeTempMsg(UnionCampWarBoxNoticeData boxNoticeData){
        UnionCampWar.UnionCampBoxNoticeTemp.Builder builder = UnionCampWar.UnionCampBoxNoticeTemp.newBuilder();
        builder.setUserName(boxNoticeData.getUserName());
        builder.setRewards(boxNoticeData.getRewards());
        builder.setTime(boxNoticeData.getOpenTime());
        builder.setServerId(boxNoticeData.getSererId());
        return builder;
    }
}
